--解析globalTableCommandTable生成要执行的命令
--print("Command execute lua")
local localTableCommandTokenTable	= {}
-----------------------------------------------------------------------------------------------------------------------------------------
--common tools 
-----------------------------------------------------------------------------------------------------------------------------------------
require(globalStrModuleUtilities)
-----------------------------------------------------------------------------------------------------------------------------------------
--自己生成的文件放到llmake-target里面
-----------------------------------------------------------------------------------------------------------------------------------------
local targetPath = globalStrRootDir.."/llmake-bc-target/"
local tmpTargetCommandStr = "${MKDIR} "..targetPath
table.insert(globalTableCommandTable,tmpTargetCommandStr)
for i,v in pairs(globalTableTargetPathTable) do
	local tmpTargetCommandStr = ""
--	print(i,v,globalTableTargetTypeTable[i][1])
	local baseName = luaGetBaseName(v)
	local pathName = luaGetPathName(v)
	if "EXEC" == globalTableTargetTypeTable[i][1] then
		local distName = targetPath..i..".bc"
		local srcName = pathName.."/"..i..".bc"
		if globalTableEnvVarOfSystemExpress["MINGW"] then
			srcName= pathName.."/"..i..".exe.bc"
		end
		tmpTargetCommandStr = "${CP} "..srcName.." "..distName
	else 
		tmpTargetCommandStr = "${CP} "..v.." "..targetPath..baseName
	end
	table.insert(globalTableCommandTable,tmpTargetCommandStr)
end 
-----------------------------------------------------------------------------------------------------------------------------------------
--打印Command
-----------------------------------------------------------------------------------------------------------------------------------------
if globalBoolLuaDebugOutputFlag then
	print("-----------globalTableCommandTable start-----------")
	for i,v in pairs(globalTableCommandTable) do 
		print(i,v)
	end
	print("-----------globalTableCommandTable end-----------")
end
-----------------------------------------------------------------------------------------------------------------------------------------
--读取实际命令
-----------------------------------------------------------------------------------------------------------------------------------------
dofile(globalStrLLMakeHomeBinPath.."/compile.conf")
-----------------------------------------------------------------------------------------------------------------------------------------
--globalTableCommandTable分解成Token，然后置换命令
-----------------------------------------------------------------------------------------------------------------------------------------
for i,v in pairs(globalTableCommandTable) do 
--	print(i,v)
	localTableCommandTokenTable[i] = parseCommand2Token(v)
	local t = localTableCommandTokenTable[i]
	local cmd = t[1]
	if nil == cmd then
		print("Unknown Command Option")
		os.exit(-1)
	end

	if "${CC}" == cmd then
		localTableCommandTokenTable[i][1] = CC
	elseif "${CXX}" == cmd then
		localTableCommandTokenTable[i][1] = CXX
	elseif "${BC_LINK}" == cmd then
		localTableCommandTokenTable[i][1] = BC_LINK
	elseif "${AR}" == cmd then
		localTableCommandTokenTable[i][1] = AR
	elseif "${LD_LIB}" == cmd then
		localTableCommandTokenTable[i][1] = LD_LIB
	elseif "${LD_EXE}" == cmd then
		localTableCommandTokenTable[i][1] = LD_EXE
	elseif "${MKDIR}" == cmd then
		localTableCommandTokenTable[i][1] = MKDIR
	elseif "${CP}" == cmd then
		localTableCommandTokenTable[i][1] = CP
	else
		print("Unknown Command")
	end
	for k,z in pairs(localTableCommandTokenTable[i]) do
--bug	debug	print("before change",k,z)
		local option = string.sub(localTableCommandTokenTable[i][k],1,2)
		if "-D" ~= option then
			localTableCommandTokenTable[i][k] = checkAndSimplePath(z)
		end
--bug debug		print("after change",k,localTableCommandTokenTable[i][k])
	end
end
for i,v in pairs(localTableCommandTokenTable) do
	local commandStr = table.concat(v," ")
	print(commandStr)
	local ret = os.execute(commandStr)
	if true == globalBoolStopAtExecError then
		if 0 ~= ret then
			os.exit(-1)
		end
	end
end

local targetPath = globalStrRootDir.."/llmake-bc-target/Dependence.txt"
io.output(targetPath)
for i,v in pairs (globalTableTargetDependenceTable) do
	io.write(v.."\n")
end
io.close()
globalStringTargetDependenceFile = targetPath
